home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 21
/
Cream of the Crop 21 (Terry Blount) (October 1996).iso
/
utility
/
rexxalgo.zip
/
RXALGO01.CMD
< prev
next >
Wrap
OS/2 REXX Batch file
|
1996-07-15
|
18KB
|
491 lines
/* REXX **********************************************/
/* */
/* Description: This file is the collection of some */
/* : Rexx-algorithms. Following templates */
/* : are placed at your's disposal at the */
/* : moment: */
/* : 1. Binary search */
/* : 2. Bubble sort */
/* : 3. Insertion sort */
/* : 4. Quick sort */
/* : 5. Shell sort */
/* : 6. Square root */
/* : 7. Digital Audio Player (mciRexx) */
/* : 8. Translation to lower case */
/* : 9. Translation date to the julian */
/* : date */
/* : 10. Translation julian date to the */
/* : date */
/* : All these code templates are written */
/* : as internal subroutines. */
/* */
/* Author.....: Janosch R. Kowalczyk */
/* Oberwaldstr. 42 */
/* 63538 Grosskrotzenburg / Germany */
/* Tel: +49 (0)6186 201676 */
/* Fax: +49 (0)6186 470 */
/* Compuserve: 101572,2160 */
/* */
/* Create date: 26 May 1996 */
/* Version....: 1.0 */
/* */
/* Changes....: No */
/* */
/* Made use of GREED. 26 May 1996 / 12:29:24 JRK */
/*****************************************************/
Say 'This file is the collection of the sample internal'
Say 'Rexx-subroutines with some necessary algorythms such'
Say 'as: various sorts, search, square root...'
Say
Say 'Refer to the source code of this file for more'
Say 'informations, please.'
Say
Say 'Call the sample test-routine named TESTALG1.CMD to'
Say 'test these procedures.'
Exit
/*===============(Internal subroutines)==============*/
/*==================(Binary search)==================*/
/* :-)) */
/* Name.......: BiSearch */
/* */
/* Function...: Search a stem variable for a value */
/* Call parm..: Search value */
/* Returns....: 0 if nothing found */
/* index of the found value */
/* Sample call: found_index = BiSearch(value) */
/* If found_index = 0 Then */
/* Say 'Value' value 'not found!' */
/* Else */
/* Say stem.found_index */
/* */
/* Notes......: The elements to search for must be */
/* saved in the stem named so as the */
/* stem in this Procedure (in this case */
/* "STEM.") */
/* stem.0 must contain the number of */
/* elements in stem. */
/* The stem-variable must be in the */
/* sorted order */
/* */
/* Changes....: No */
/* */
/*===================================================*/
BiSearch: Procedure Expose stem.
Parse Arg value /* Search value */
found = 0 /* Index of the found Item */
bottom = 1 /* Index of the first Item */
top = stem.0 /* Index of the last Item */
/*------------------(Binary Search)------------------*/
Do While found = 0 & top >= bottom
mean = (bottom + top) % 2
If value = stem.mean Then
found = mean
Else If value < stem.mean Then
top = mean - 1
Else
bottom = mean + 1
End /* Do While */
Return found
/*===================(Bubble sort)===================*/
/* :-I */
/* Name.......: BubSort */
/* */
/* Function...: Bubble Sort for a stem variable */
/* Call parm..: No */
/* Returns....: nothing (NULL string) */
/* */
/* Sample call: Call BubSort */
/* */
/* Notes......: The elements to sort for must be */
/* saved in the stem named so as the */
/* stem in this Procedure (in this case */
/* "STEM.") */
/* stem.0 must contain the number of */
/* elements in stem. */
/* */
/* Changes....: No */
/* */
/*===================================================*/
BubSort: Procedure Expose stem.
/*------------(Bubble Sort for the Stem)-------------*/
Do i = stem.0 To 1 By -1 Until flip_flop = 1
flip_flop = 1
Do j = 2 To i
m = j - 1
If stem.m > stem.j Then Do
xchg = stem.m
stem.m = stem.j
stem.j = xchg
flip_flop = 0
End /* If stem.m ... */
End /* Do j = 2 ... */
End /* Do i = stem.0 ... */
Return ''
/*=================(Insertion sort)==================*/
/* :-! */
/* Name.......: InsSort */
/* */
/* Function...: Insertion Sort for a stem variable */
/* Call parm..: No */
/* Returns....: nothing (NULL string) */
/* */
/* Sample call: Call InsSort */
/* */
/* Notes......: The elements to sort for must be */
/* saved in the stem named so as the */
/* stem in this Procedure (in this case */
/* "STEM.") */
/* stem.0 must contain the number of */
/* elements in stem. */
/* */
/* Changes....: No */
/* */
/*===================================================*/
InsSort: Procedure Expose stem.
/*------------(Insertion Sort for Stem)--------------*/
Do x = 2 To stem.0
xchg = stem.x
Do y = x - 1 By -1 To 1 While stem.y > xchg
xchg = stem.x
stem.x = stem.y
stem.y = xchg
x = y
End /* Do y = x... */
stem.x = xchg
End /* Do x = 2 ... */
Return ''
/*====================(Quick sort)===================*/
/* :-)) */
/* Name.......: QSort */
/* */
/* Function...: Quick Sort for a stem variable */
/* Call parm..: No */
/* Returns....: Left-Right span */
/* */
/* Sample call: Call QSort */
/* */
/* Notes......: The elements to sort for must be */
/* saved in the stem named so as the */
/* st